package com.ysd.service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

import com.ysd.entity.User;
import com.ysd.util.DBManage;

/**
 * Servlet implementation class usertwoService
 */
@WebServlet("/usertwoService")
public class usertwoService extends HttpServlet {
	
	public User login(String name) {
		User u=null;
		try {
			Connection conn=DBManage.getConn();
			Statement stam= conn.createStatement();
			String sql="SELECT id,name,phone,imgurl,password,account,gender from user where name='"+name+"'";
			ResultSet rs=stam.executeQuery(sql);
			while(rs.next()) {
				u=new User(rs.getInt("id"),rs.getString("name"),rs.getString("phone"),rs.getString("imgurl"),rs.getString("password"),rs.getString("account"),rs.getString("gender"));
				u.setId(rs.getInt("id"));
				u.setName(rs.getString("name"));
				u.setPhone(rs.getString("phone"));
				u.setImgurl(rs.getString("imgurl"));
				u.setPassword(rs.getString("password"));
				u.setAccount(rs.getString("account"));
				u.setGender(rs.getString("gender"));
			}
			
			DBManage.colseAll(rs, stam, conn);
		} catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return u;
	}

}
